package com.itheima.dao;

import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CheckItemDao {
    /**
     * 查询所有
     *
     * @return
     */
    @Select("select * from t_checkitem")
    List<CheckItem> findAll();

    /**
     * 添加数据
     *
     * @param checkItem
     */
    @Insert("insert into t_checkitem values(null,#{code},#{name},#{sex},#{age},#{price},#{type},#{attention},#{remark})")
    void addCheckItem(CheckItem checkItem);

    /**
     * 条件查询
     *
     * @param queryString
     * @return
     */
    @Select("<script>select * from t_checkitem  <where>\n" +
            "            <if test=\"value!=null and value.length > 0\">\n" +
            "                code like concat('%',#{value},'%') or name like concat('%',#{value},'%')\n" +
            "            </if>\n" +
            "        </where>" +
            "</script>")
    List<CheckItem> findByCondition(String queryString);

    /**
     * 更新数据
     *
     * @param checkItem
     */
    @Update("update t_checkitem set code=#{code}, name=#{name},sex=#{sex},age=#{age},price=#{price},type=#{type},attention=#{attention},remark=#{remark} where id=#{id}")
    void updateCheckItem(CheckItem checkItem);

    /**
     * 查询中间表
     *
     * @param id
     * @return
     */
    @Select("select count(1) from t_checkgroup_checkitem where checkitem_id=#{id}")
    Integer findCountByCheckItemId(Integer id);

    /**
     * 删除数据
     *
     * @param id
     */
    @Delete("delete from t_checkitem where id = #{id}")
    void delete(Integer id);


    @Select("select * from t_checkitem tc,t_checkgroup_checkitem tcc where tc.id=tcc.checkitem_id and checkgroup_id=#{checkGroupId}")
    List<CheckItem> findCheckItemByCheckGroupId(Integer checkGroupId);
}
